home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / include / smg.h < prev    next >
C/C++ Source or Header  |  1992-01-23  |  2KB  |  77 lines

  1. /* --------------------------------------------------------------------------
  2.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  3.  *
  4.  * You can use and distribute this software under the terms of the licence
  5.  * you should have received along with this program.
  6.  * If not or if you want additional information, write to
  7.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  8.  * D-7500 Karlsruhe 1, Germany.
  9.  * --------------------------------------------------------------------------
  10.  */
  11. #ifndef SMGH
  12. #define SMGH 1
  13.  
  14. #include <stream.h>
  15. #include <string.h>
  16.  
  17. class sos_Container;
  18. class sos_String;
  19.  
  20. class smg_String_ptr
  21. {  
  22. #ifdef SMG_NEED_PUBLIC_FOR_INIT
  23. public:
  24. #else
  25.    friend class smg_String;
  26.    friend ostream& operator<< (ostream&, const smg_String&);
  27. #endif
  28.    char managed;
  29.    short rc;
  30.    char *c;
  31. };
  32. extern smg_String_ptr smg_empty_string_ptr;
  33.  
  34. enum smg_access {SMG_COPY, SMG_TRANSFER, SMG_BORROW};
  35.  
  36. class smg_String
  37. {  smg_String_ptr *ptr;
  38.    friend ostream& operator<< (ostream&, const smg_String&);
  39. public:
  40.  
  41.    smg_String () { ptr = &smg_empty_string_ptr; ++smg_empty_string_ptr.rc; }
  42.    smg_String (char*, const smg_access access = SMG_BORROW);
  43.    smg_String (sos_String);
  44.    smg_String (const sos_Int, const int decimal_mode = 1);
  45.  
  46.    smg_String (const smg_String &s) { ptr = s.ptr; ptr->rc++; }
  47.    smg_String& operator= (const smg_String&);
  48.  
  49.    ~smg_String () { if (--ptr->rc == 0) { if (ptr->managed) delete ptr->c;
  50.                       delete ptr; } }
  51.  
  52.    char* make_Cstring (const smg_access access = SMG_COPY) const;
  53.  
  54.    sos_String make_String (const sos_Container) const;
  55.  
  56.    int length () const { return strlen (ptr->c); }
  57.  
  58.    int compare (const smg_String &s) const
  59.     { return strcmp (ptr->c, s.ptr->c); }
  60.    int equal (const smg_String &s)   const
  61.     { return strcmp (ptr->c, s.ptr->c) == 0; }
  62.    smg_String& operator += (const smg_String& s) const
  63.     { return (*this += s.ptr->c); }
  64.    smg_String operator + (const smg_String& s) const 
  65.     { return (*this + s.ptr->c); }
  66.    smg_String clone () const;
  67.  
  68.    int compare (const char *c) const { return strcmp (ptr->c, c); }
  69.    int equal (const char *c)   const { return strcmp (ptr->c, c) == 0; }
  70.    smg_String& operator += (const char*) const;
  71.    smg_String operator + (const char*) const;
  72. };
  73.  
  74. ostream& operator<< (ostream&, const smg_String&);
  75.  
  76. #endif
  77.